/*
 * CargoForm.java
 *
 * Created on 4 de diciembre de 2005, 21:55
 */
package org.fiel.admin.struts.forms;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import org.fiel.admin.dao.RecursoDAO;

/**
 * @author Ing. Luis Pablo Gallo
 */
public class CargoForm extends ActionForm{
    private String id = null;
    private String nombre = null;
    private String orden = null;

    /** Creates a new instance of AreaForm */
    public CargoForm() {
    }

    public void reset(ActionMapping mapping, HttpServletRequest request){
        this.id = null;
        this.nombre = null;
    }

    public ActionErrors validate( ActionMapping mapping
                                , HttpServletRequest request ){
        ActionErrors errors = new ActionErrors();
        
        if(this.id==null || this.id.length()<1){
            errors.add("id", new ActionError("error.id.requerido"));
        }
        if(this.nombre==null || this.nombre.length()<1){
            errors.add("nombre", new ActionError("error.nombre.requerido"));
        }
        
        return errors;
    }

    public List getRecursosAreas(String areaId)
    throws Exception{
        RecursoDAO dao = new RecursoDAO();
        return dao.retrieveByAreaCargo(areaId, this.id);
    }
    
    public List getRecursosSinArea()
    throws Exception{
        RecursoDAO dao = new RecursoDAO();
        return dao.retrieveSinArea(this.id);
    }
    
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public String getOrden() {
        return orden;
    }

    public void setOrden(String orden) {
        this.orden = orden;
    }
    
}
